from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-03-02 14:02:18.467435
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 02, Mar, 2022
Time: 14:02:23
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.3443
Nobs: 583.000 HQIC: -48.7558
Log likelihood: 6933.77 FPE: 5.14617e-22
AIC: -49.0186 Det(Omega_mle): 4.41579e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.350679 0.067873 5.167 0.000
L1.Burgenland 0.107955 0.041229 2.618 0.009
L1.Kärnten -0.110639 0.021513 -5.143 0.000
L1.Niederösterreich 0.190627 0.086117 2.214 0.027
L1.Oberösterreich 0.124629 0.085051 1.465 0.143
L1.Salzburg 0.256717 0.043675 5.878 0.000
L1.Steiermark 0.036651 0.057690 0.635 0.525
L1.Tirol 0.101627 0.046549 2.183 0.029
L1.Vorarlberg -0.068236 0.041039 -1.663 0.096
L1.Wien 0.017089 0.075591 0.226 0.821
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.051524 0.146194 0.352 0.725
L1.Burgenland -0.038023 0.088803 -0.428 0.669
L1.Kärnten 0.041649 0.046336 0.899 0.369
L1.Niederösterreich -0.205093 0.185488 -1.106 0.269
L1.Oberösterreich 0.459348 0.183193 2.507 0.012
L1.Salzburg 0.282068 0.094073 2.998 0.003
L1.Steiermark 0.114308 0.124260 0.920 0.358
L1.Tirol 0.304632 0.100262 3.038 0.002
L1.Vorarlberg 0.026308 0.088395 0.298 0.766
L1.Wien -0.027552 0.162817 -0.169 0.866
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199786 0.034618 5.771 0.000
L1.Burgenland 0.088435 0.021028 4.206 0.000
L1.Kärnten -0.007365 0.010972 -0.671 0.502
L1.Niederösterreich 0.239320 0.043923 5.449 0.000
L1.Oberösterreich 0.162072 0.043380 3.736 0.000
L1.Salzburg 0.039695 0.022276 1.782 0.075
L1.Steiermark 0.026568 0.029424 0.903 0.367
L1.Tirol 0.081900 0.023742 3.450 0.001
L1.Vorarlberg 0.053868 0.020932 2.574 0.010
L1.Wien 0.117805 0.038555 3.056 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.119587 0.034627 3.454 0.001
L1.Burgenland 0.042471 0.021034 2.019 0.043
L1.Kärnten -0.013228 0.010975 -1.205 0.228
L1.Niederösterreich 0.169829 0.043934 3.866 0.000
L1.Oberösterreich 0.338522 0.043390 7.802 0.000
L1.Salzburg 0.099649 0.022282 4.472 0.000
L1.Steiermark 0.111206 0.029432 3.778 0.000
L1.Tirol 0.089834 0.023748 3.783 0.000
L1.Vorarlberg 0.060547 0.020937 2.892 0.004
L1.Wien -0.018652 0.038564 -0.484 0.629
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.124619 0.065155 1.913 0.056
L1.Burgenland -0.045298 0.039578 -1.145 0.252
L1.Kärnten -0.045399 0.020651 -2.198 0.028
L1.Niederösterreich 0.135753 0.082668 1.642 0.101
L1.Oberösterreich 0.162419 0.081645 1.989 0.047
L1.Salzburg 0.285176 0.041926 6.802 0.000
L1.Steiermark 0.057765 0.055380 1.043 0.297
L1.Tirol 0.157270 0.044685 3.520 0.000
L1.Vorarlberg 0.097183 0.039396 2.467 0.014
L1.Wien 0.073587 0.072564 1.014 0.311
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.079497 0.050784 1.565 0.117
L1.Burgenland 0.024843 0.030848 0.805 0.421
L1.Kärnten 0.053384 0.016096 3.317 0.001
L1.Niederösterreich 0.188475 0.064434 2.925 0.003
L1.Oberösterreich 0.332916 0.063637 5.231 0.000
L1.Salzburg 0.033387 0.032679 1.022 0.307
L1.Steiermark 0.006406 0.043165 0.148 0.882
L1.Tirol 0.119347 0.034829 3.427 0.001
L1.Vorarlberg 0.065560 0.030706 2.135 0.033
L1.Wien 0.097973 0.056559 1.732 0.083
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170960 0.061346 2.787 0.005
L1.Burgenland 0.005177 0.037263 0.139 0.889
L1.Kärnten -0.065924 0.019444 -3.391 0.001
L1.Niederösterreich -0.107622 0.077834 -1.383 0.167
L1.Oberösterreich 0.208663 0.076871 2.714 0.007
L1.Salzburg 0.053940 0.039475 1.366 0.172
L1.Steiermark 0.247996 0.052142 4.756 0.000
L1.Tirol 0.499762 0.042072 11.879 0.000
L1.Vorarlberg 0.064602 0.037092 1.742 0.082
L1.Wien -0.074343 0.068321 -1.088 0.277
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161450 0.068045 2.373 0.018
L1.Burgenland -0.002188 0.041333 -0.053 0.958
L1.Kärnten 0.062939 0.021567 2.918 0.004
L1.Niederösterreich 0.165726 0.086334 1.920 0.055
L1.Oberösterreich -0.055333 0.085266 -0.649 0.516
L1.Salzburg 0.208325 0.043786 4.758 0.000
L1.Steiermark 0.138606 0.057836 2.397 0.017
L1.Tirol 0.055850 0.046666 1.197 0.231
L1.Vorarlberg 0.147085 0.041143 3.575 0.000
L1.Wien 0.120646 0.075782 1.592 0.111
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.392307 0.039943 9.822 0.000
L1.Burgenland -0.004569 0.024263 -0.188 0.851
L1.Kärnten -0.021290 0.012660 -1.682 0.093
L1.Niederösterreich 0.199534 0.050679 3.937 0.000
L1.Oberösterreich 0.231915 0.050052 4.633 0.000
L1.Salzburg 0.036691 0.025703 1.428 0.153
L1.Steiermark -0.016386 0.033950 -0.483 0.629
L1.Tirol 0.090515 0.027394 3.304 0.001
L1.Vorarlberg 0.050809 0.024151 2.104 0.035
L1.Wien 0.043290 0.044485 0.973 0.330
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036569 0.102092 0.167874 0.138299 0.094189 0.080870 0.032406 0.208837
Kärnten 0.036569 1.000000 -0.027866 0.131384 0.048419 0.084905 0.443829 -0.067126 0.089201
Niederösterreich 0.102092 -0.027866 1.000000 0.309611 0.118230 0.269808 0.065491 0.151234 0.287818
Oberösterreich 0.167874 0.131384 0.309611 1.000000 0.212369 0.294682 0.165369 0.134854 0.234763
Salzburg 0.138299 0.048419 0.118230 0.212369 1.000000 0.122355 0.091064 0.104397 0.122593
Steiermark 0.094189 0.084905 0.269808 0.294682 0.122355 1.000000 0.133630 0.105583 0.032950
Tirol 0.080870 0.443829 0.065491 0.165369 0.091064 0.133630 1.000000 0.062802 0.150993
Vorarlberg 0.032406 -0.067126 0.151234 0.134854 0.104397 0.105583 0.062802 1.000000 -0.005295
Wien 0.208837 0.089201 0.287818 0.234763 0.122593 0.032950 0.150993 -0.005295 1.000000